/*
 * Copyright 2011 Kim Lindhardt Madsen
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package dk.lindhardt.gwt.geie.client.edit;

import com.google.gwt.user.client.ui.Widget;
import dk.lindhardt.gwt.geie.shared.Cell;

import java.io.Serializable;
import java.util.List;

/**
 * User: AnAmuser
 * Date: 17-08-11
 * <p/>
 *
 */
public interface ValueEditor {

   interface EditHandler {
      /**
       * Called when the edit is confirmed
       */
      void onEditConfirmed();

      /**
       * Called when the edit is cancelled
       */
      void onEditCancelled();
   }

   /**
    * Returns whether this editor is listening for clicks on the table. If true clicks on the table calls
    * {@link #handleTableSelection(java.util.List)} where the cell parameter is the cell that was
    * clicked.
    * @return whether this editor is listing for clicks on the table.
    */
   boolean isListeningForTableSelections();

   /**
    * Handles selections on the table. Is only called if {@link #isListeningForTableSelections()} returns true at the time of
    * the click.
    * @param cells the cells that was selected
    */
   void handleTableSelection(List<Cell> cells);

   /**
    * Gets the widget used for editing the value in the cell
    * @return the edit widget
    */
   Widget getInputWidget();

   /**
    * Sets the initial value in the input widget
    * @param value the value
    */
   void setInitialInputValue(Serializable value);

   /**
    * Creates a new cell from the value in the input widget
    * @return the new cell
    */
   Cell createNewCell();

   /**
    * Validates the input before submitting the new cell
    * @return validated
    */
   boolean validate();
}
